import random
import time
from multiprocessing import current_process, Process


class MyProcess(Process):
    def __init__(self, name):
        Process.__init__(self)
        self.name = name

    def run(self):
        time.sleep(random.randint(1, 2))
        print('%s 执行完毕' % self.name)


if __name__ == '__main__':
    print('%s 主进程开始执行' % current_process().name)
    lst = []
    for i in range(1, 10):
        p = MyProcess('Process-%s' % i)
        p.start()
        lst.append(p)

    for item in lst:
        item.join()
    print("主进程执行完毕")
